package com.medical.client.controller.utils;
import com.medical.client.model.Context;
import javafx.scene.Parent;
import javafx.scene.control.ProgressIndicator;
import javafx.scene.layout.Pane;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import javafx.stage.Modality;
import javafx.scene.Scene;
/**
 * @ClassName: LoadingUtils
 * @Description: TODO
 * @Author: JackyLee
 * @Date: 2024/6/18 12:03
 **/
public class LoadingUtils {
    private static ProgressIndicator progressIndicator;
    private static StackPane loadingContainer; // 用于作为最顶层的容器

    private LoadingUtils() {
        // 私有构造函数，防止实例化
    }

    public static void show(){
        if(progressIndicator==null){
            loadingContainer = (StackPane) Context.stackPanel.get("stackPane");

            progressIndicator = new ProgressIndicator();
            progressIndicator.setStyle("-fx-progress-color: blue;"); // 设置进度指示器的颜色（可选）
            progressIndicator.setScaleX(2); // 放大X轴
            progressIndicator.setScaleY(2); // 放大Y轴

            loadingContainer.getChildren().add(progressIndicator);
        }
        progressIndicator.setVisible(true);
    }

    public static void close() {
        progressIndicator.setVisible(false);
    }

    private static void positionInCenter(Pane pane, StackPane stackPane) {
        double centerX = (pane.getWidth() - stackPane.prefWidth(-1)) / 2;
        double centerY = (pane.getHeight() - stackPane.prefHeight(-1)) / 2;
        stackPane.setLayoutX(centerX);
        stackPane.setLayoutY(centerY);
    }
}
